import { body } from 'express-validator';
import {
  code, name, begin_date, end_date, version, reference
} from './common';

const state = body('state')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ max: 50 })
  .withMessage('state length limit 50')
  .bail({ level: 'request' });

const city = body('city')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ max: 50 })
  .withMessage('city length limit 50')
  .bail({ level: 'request' });

const address = body('address')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ max: 200 })
  .withMessage('address length limit 200')
  .bail({ level: 'request' });

const group = body('group')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ max: 50 })
  .withMessage('group length limit 50')
  .bail({ level: 'request' });

const owner = body('owner')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ max: 50 })
  .withMessage('owner length limit 50')
  .bail({ level: 'request' });

const star = body('star')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ max: 10 })
  .withMessage('star length limit 10')
  .bail({ level: 'request' });

const rooms = body('rooms')
  .optional({ values: 'falsy' })
  .trim()
  .isInt({ min: 0, max: 99999 })
  .withMessage('rooms limit between 0 and 99999')
  .bail({ level: 'request' })
  .toInt(10);

const contact_name = body('contact_name')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ min: undefined, max: 50 })
  .withMessage('contact name length limit between 50')
  .bail({ level: 'request' });

const contact_phone = body('contact_phone')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ min: undefined, max: 50 })
  .withMessage('contact phone length limit 50')
  .bail({ level: 'request' });

export const create = [
  code,
  name,
  begin_date,
  end_date,
  state,
  city,
  address,
  group,
  owner,
  star,
  rooms,
  contact_name,
  contact_phone,
  reference
];

export const update = [
  name,
  begin_date,
  end_date,
  state,
  city,
  address,
  group,
  owner,
  star,
  rooms,
  contact_name,
  contact_phone,
  reference,
  version
];
